package payrechargelogic

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeFailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRechargeFailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeFailLogic {
	return &RechargeFailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// RechargeFail 充值失败处理
func (l *RechargeFailLogic) RechargeFail(in *rpc.NotifyFailRequest) (*rpc.NotifyResponse, error) {

	err := recharge.NewRechargeOrderModel(l.ctx, l.svcCtx.Db).
		UpdateStatusFailed(in.OrderNo, in.ReturnJson)
	if err != nil {
		return nil, xerrors.ErrUpdate
	}

	return &rpc.NotifyResponse{}, nil
}
